/-app ...
/-app/tests ...
TestCase.ts
TestPage.ts
Application.ts
/-boot
/-imports
/-storage
/-tests
_sampleTests.ts
/-typings
stringUtils.ts
teapo.html
31
 
32
        if (!this.notStarted.length)
33
          return;
34
 
35
        this._startOne();
36
 
37
        if (!this.notStarted.length)
38
          return;
39
        
40
        if (Date.now() >= nextRest) {
41
          this._queueWorkItem(this._continueStartingClosure);
42
          return;
43
        }
44
      }
45
    }
46
 
47
    private _startOne() {
48
      var nextTest = this.notStarted.shift();
49
      this.running.push(nextTest);
50
 
51
      nextTest.state.subscribe(newState => {
52
        var targetCollection =
53
          newState === TestCase.State.Succeeded ? this.succeeded :
54
          newState === TestCase.State.Failed ? this.failed :
55
          null;
56
 
57
        if (targetCollection) { 
58
          var targetCollectionArray = targetCollection();
59
          
60
          // iterate backwards, as the tests are likely to complete in the order they started
61
          for (var i = targetCollectionArray.length - 1; i>=0; i--) { 
62
            var t = targetCollectionArray[i];
63
            if (nextTest.name > t.name) {
64
              targetCollection.splice(i + 1, 0, nextTest);
65
              return;
66
            }
67
          }
68
 
69
          targetCollection.unshift(nextTest);
70
        }
71
      });
72
    }
73
 
74
    private _loadTests(namespace: any) {
75
 
76
      var byName: { [name: string]: TestCase; } = {};
77
      var names: string[] = [];
78
 
79
      TestPage.forEachTest(namespace, (name, test) => {
80
        var testCase = new TestCase(name, test);
81
        byName[name] = testCase;
82
        names.push(name);
83
      });
84
 
85
      names.sort();
86
      names.forEach(name => {
87
        var testCase = byName[name];
88
        this.all.push(testCase);
89
      });
90
 
91
      this.notStarted(this.all);
92
 
93
    }
94
 
95
    static forEachTest(namespace: any, callback: (name: string, test: () => void) => void) {
96
      for (var k in namespace) if (namespace.hasOwnProperty(k)) {
97
        var t = namespace[k];
98
        if (typeof (t) === 'function') {
99
          callback(k, t);
100
        }
101
      }
102
    }
103
  }
104
 
105
}